package com.cgbl.service.vm

import android.app.Application
import android.os.Bundle
import android.text.TextUtils
import androidx.databinding.ObservableField
import com.robot.base.base.vm.GLBaseViewModel
import com.robot.base.configs.AppConstants
import com.robot.base.util.ToastUtils
import com.robot.base.util.arouter.ARouterUtil
import me.goldze.mvvmhabit.binding.command.BindingAction
import me.goldze.mvvmhabit.binding.command.BindingCommand

class AddMemberViewModel(application: Application) : GLBaseViewModel(application) {

    val keywordField = ObservableField<String>()

    private var selectType = AppConstants.BundleValue.SELECT_MEMBER_TYPE_MANAGER


    val toSearchMemberCommand = BindingCommand<Any>(BindingAction {
        if (TextUtils.isEmpty(keywordField.get())) {
            ToastUtils.showShort("请输入搜索关键字!")
            return@BindingAction
        }
        ARouterUtil.goToActivityWithBundle(AppConstants.Router.Project.A_MEMBER_SEARCH,
            Bundle().apply {
                putString(AppConstants.BundleKey.KEYWORD, keywordField.get())
                putInt(
                    AppConstants.BundleKey.SELECT_MEMBER_TYPE,
                    selectType
                )
            })
        finish()
    })

    fun setSelectType(selectType: Int) {
        this.selectType = selectType
    }

}